﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.Rules.CUiSearchAndReplace
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Planning.DotNetComponents;


namespace DnProcessSimulateCommands.RenameTool.Rules;

public class CUiSearchAndReplace : RuleWindowBase, IComponentConnector
{
  private const int argsLength = 6;
  internal System.Windows.Controls.RadioButton radioButtonEntireName;
  internal System.Windows.Controls.RadioButton radioButtonSearch;
  internal System.Windows.Controls.TextBox textBoxSearch;
  internal System.Windows.Controls.CheckBox checkBoxMatchCase;
  internal System.Windows.Controls.CheckBox checkBoxMatchEntireName;
  internal System.Windows.Controls.CheckBox checkBoxUseWildcards;
  internal TextBlock textBlockReplace;
  internal System.Windows.Controls.TextBox textBoxReplace;
  internal System.Windows.Controls.TextBox textBoxEnum;
  internal System.Windows.Controls.TextBox textBoxStep;
  internal System.Windows.Controls.Button buttonAddEnumerator;
  internal System.Windows.Controls.CheckBox unlimitedChkBx;
  internal System.Windows.Controls.Button buttonAddAttribute;
  internal System.Windows.Controls.Button btnOK;
  internal System.Windows.Controls.Button btnCancel;
  private bool _contentLoaded;

  public CUiSearchAndReplace(Window parent)
  {
    this.InitializeComponent();
    ((Window) this).Owner = parent;
    this.textBoxReplace.Focus();
    // ISSUE: explicit non-virtual call
    __nonvirtual (((Window) this).Title) = XamlResourceManager.GetString("RENAME_TOOL_TITLE_SEARCHREPLACE");
    if (CApRenameToolManager.GetInstance().IsRunningInDesigner())
      return;
    this.buttonAddAttribute.Visibility = Visibility.Collapsed;
    ((FrameworkElement) this).MinHeight = ((FrameworkElement) this).MinHeight - 29.0;
    ((FrameworkElement) this).MaxHeight = ((FrameworkElement) this).MaxHeight - 29.0;
  }

  public override object[] Args
  {
    get
    {
      return new object[6]
      {
        (object) this.radioButtonEntireName.IsChecked.Value,
        (object) this.textBoxSearch.Text,
        (object) this.checkBoxMatchCase.IsChecked.Value,
        (object) this.textBoxReplace.Text,
        (object) this.checkBoxMatchEntireName.IsChecked.Value,
        (object) this.checkBoxUseWildcards.IsChecked.Value
      };
    }
    set
    {
      if (value.Length != 6)
        throw new FormatException("Four values expected.");
      this.radioButtonEntireName.IsChecked = value[0] is bool && value[1] is string && value[2] is bool && value[3] is string && value[4] is bool && value[5] is bool ? new bool?((bool) value[0]) : throw new FormatException("Wrong types supplied.");
      this.radioButtonSearch.IsChecked = new bool?(!(bool) value[0]);
      this.textBoxSearch.Text = (string) value[1];
      this.checkBoxMatchCase.IsChecked = new bool?((bool) value[2]);
      this.textBoxReplace.Text = (string) value[3];
      this.checkBoxMatchEntireName.IsChecked = new bool?((bool) value[4]);
      this.checkBoxUseWildcards.IsChecked = new bool?((bool) value[5]);
    }
  }

  public override RuleMessage Validate()
  {
    bool? isChecked = this.radioButtonSearch.IsChecked;
    bool flag = true;
    if (isChecked.GetValueOrDefault() == flag & isChecked.HasValue && this.textBoxSearch.Text.Length == 0)
      return new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_SEARCH_AND_REPLACE_VALIDATION_EMPTY_SEARCH"));
    RuleMessage ruleMessage = new PartialStringParser().Parse(this.textBoxReplace.Text);
    return !ruleMessage.Success ? ruleMessage : new RuleMessage(true);
  }

  private void btnOK_Click(object sender, RoutedEventArgs e)
  {
    ((Window) this).DialogResult = new bool?(true);
  }

  private void buttonAddEnumerator_Click(object sender, RoutedEventArgs e)
  {
    if (this.textBoxEnum.Text == "")
    {
      int num1 = (int) TxMessageBox.Show(XamlResourceManager.GetString("RENAME_TOOL_PARSER_WRONG_ENUM"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    else
    {
      string enumeratorString = PartialStringParser.GetEnumeratorString(this.textBoxEnum.Text, this.textBoxStep.Text, this.unlimitedChkBx.IsChecked.Value);
      RuleMessage ruleMessage = new PartialStringParser().Parse(enumeratorString);
      if (!ruleMessage.Success)
      {
        int num2 = (int) TxMessageBox.Show(ruleMessage.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      else
        this.textBoxReplace.Text += enumeratorString;
    }
  }

  private void textBoxSearch_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
  {
    if (!this.textBoxSearch.IsEnabled)
      return;
    this.textBoxSearch.Focus();
    this.textBoxSearch.Select(this.textBoxSearch.Text.Length, 0);
  }

  private void buttonAddAttribute_Click(object sender, RoutedEventArgs e)
  {
    DncFieldSelectorDialog fieldSelectorDialog = new DncFieldSelectorDialog(true);
    fieldSelectorDialog.SetSortAttributesByNameByDefault(false);
    // ISSUE: method pointer
    fieldSelectorDialog.Filter += new FieldFilter((object) null, __methodptr(FilterSimpleTypesOnly));
    fieldSelectorDialog.OnApply += new EventHandler(this.fsd_OnApply);
    int num = (int) ((Form) fieldSelectorDialog).ShowDialog();
  }

  private void fsd_OnApply(object sender, EventArgs e)
  {
    if (!(sender is DncFieldSelectorDialog fieldSelectorDialog) || !fieldSelectorDialog.IsDirty)
      return;
    DncfFieldDef[] selectedFields = fieldSelectorDialog.SelectedFields;
    if (selectedFields.Length == 0)
      return;
    foreach (string serializedAttributesName in CApRenameToolManager.GetSerializedAttributesNames(selectedFields, '{', '}'))
      this.textBoxReplace.Text += serializedAttributesName;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/renametool/rules/cuisearchandreplace.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  internal Delegate _CreateDelegate(Type delegateType, string handler)
  {
    return Delegate.CreateDelegate(delegateType, (object) this, handler);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.radioButtonEntireName = (System.Windows.Controls.RadioButton) target;
        break;
      case 2:
        this.radioButtonSearch = (System.Windows.Controls.RadioButton) target;
        break;
      case 3:
        this.textBoxSearch = (System.Windows.Controls.TextBox) target;
        this.textBoxSearch.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.textBoxSearch_IsEnabledChanged);
        break;
      case 4:
        this.checkBoxMatchCase = (System.Windows.Controls.CheckBox) target;
        break;
      case 5:
        this.checkBoxMatchEntireName = (System.Windows.Controls.CheckBox) target;
        break;
      case 6:
        this.checkBoxUseWildcards = (System.Windows.Controls.CheckBox) target;
        break;
      case 7:
        this.textBlockReplace = (TextBlock) target;
        break;
      case 8:
        this.textBoxReplace = (System.Windows.Controls.TextBox) target;
        break;
      case 9:
        this.textBoxEnum = (System.Windows.Controls.TextBox) target;
        break;
      case 10:
        this.textBoxStep = (System.Windows.Controls.TextBox) target;
        break;
      case 11:
        this.buttonAddEnumerator = (System.Windows.Controls.Button) target;
        this.buttonAddEnumerator.Click += new RoutedEventHandler(this.buttonAddEnumerator_Click);
        break;
      case 12:
        this.unlimitedChkBx = (System.Windows.Controls.CheckBox) target;
        break;
      case 13:
        this.buttonAddAttribute = (System.Windows.Controls.Button) target;
        this.buttonAddAttribute.Click += new RoutedEventHandler(this.buttonAddAttribute_Click);
        break;
      case 14:
        this.btnOK = (System.Windows.Controls.Button) target;
        this.btnOK.Click += new RoutedEventHandler(this.btnOK_Click);
        break;
      case 15:
        this.btnCancel = (System.Windows.Controls.Button) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
